<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/jsp/common.jsp"%>
</head>
<body>
<h2>治疗仪管理</h2>
<hr>
<form action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">仪器编号：</label>
            <div class="layui-input-inline">
                <%--<input type="text" id="instrId" autocomplete="off" class="layui-input">--%>
                    <select name="instrId" id="instrId"  lay-search lay-verify="">
                        <option value="-1">请选择治疗仪</option>
                    </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">病例编号：</label>
            <div class="layui-input-inline">
                <input type="text" id="caseNo" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm" onclick="reloadData();"><i class="layui-icon layui-icon-search"></i> 搜索</button>
        </div>
    </div>
</form>
<table id="reserTable" lay-filter="reserTable"></table>
<script>
    function reloadData(){
        layui.table.reload("reserTable",{
            page:{
                curr : 1
            },
            where : {
                instrIdStr : $("#instrId").val(),
                caseNoStr : $("#caseNo").val()
            }
        })
    }

    var laydate;
    var table;
    var form ;
    var notice;

    layui.use(['table','form','laydate'],function () {
        table = layui.table;
        form = layui.form;
        laydate = layui.laydate;
        notice = layui.notice;
        //渲染表格
        table.render({
            elem: '#reserTable',
            url: '${path}/reser/list',
            page:true,
            even: true,
            toolbar:'#toolbarDemo',
            cols:[[
                {type:'radio'},
                {field:'reserveInstrId',title:'编号',width:80, sort: true},
                {field:'instrId',title:'仪器名称',templet:function (d) {
                        return d.instrId.instrName
                }},
                {field:'userId',title:'用户',templet:function (d) {
                        return d.userId.username
                    }},
                {field:'caseNo',title:'病历编号',templet:function (d) {
                        return d.caseNo.medicalRecordNo
                    }},
                {field:'reserveInstrStartDate',title:'预定开始'},
                {field:'reserveInstrFinishDate',title:'预定结束'},
                {field:'reserveInstrStatus',title:'仪器状态',templet:function x(d){
                        if (d.reserveInstrStatus == 0){
                            return"不可用"
                        }
                        return"可用"
                    }},
                {field:'memberId',title:'会员',templet:function (d) {
                        return d.memberId.memberName
                    }},
                {field:'qian',title:'钱'},
                {field:'hello', title:'操作',toolbar:'#barDemo'}
            ]]
        })

        table.on("toolbar(reserTable)",function (obj) {
            var e = obj.event;
            if (e == 'add'){
                $.get("${path}/bingliluru/yuyuezhiliaoyi",function (str) {
                    layer.open({
                        type: 1,
                        title: '预约治疗仪',
                        area: '800px',
                        maxmin: true,
                        content : str,
                        btn:['确定','取消'],
                        yes:function (index) {

                            $("#yiqiname").val($('select[name="instrId"] option:selected').text())


                            var parems = $("#yiqifrom").serialize();
                            console.log(parems)

                            $.get("${path}/reser/yuyuezhiliaoyi",parems,function (d) {

                                var caseNo = $("#caseNos").val();

                                $.get("${path}/reser/getByReserveInstr",{caseId:caseNo},function (getstr) {
                                    layer.close(index);
                                    layui.notice.init({
                                        type: "warm",
                                        autoClose: true,
                                        title: "患者 “"+getstr.reserveName+"” 预约 “"+$('select[name="instrId"] option:selected').text() +"” 成功！"
                                    });
                                })

                            })
                        }
                    })
                })
            }

        })
        table.on("tool(reserTable)",function (obj) {
            var data = obj.data;
            var e = obj.event;
            if (e == "edit"){

            }else if (e == "del"){
                layer.open({
                    title: "友情提示",
                    content:"你确定删除吗?",
                    btn:['确定','取消'],
                    yes:function () {
                        $.post("${path}/reser/batchDelete",{ids:data.reserveInstrId},function () {
                            layer.msg("删除成功了");
                            table.reload('reserTable');
                        });
                    }
                })
            }
        })

    //    获取治疗仪
        $.get("${path}/reser/zly",function (data) {
            $.each(data,function(){
                var opt = $("<option></option>").appendTo("#instrId");
                opt.text(this.instrName).val(this.instrId);
            });

            layui.form.render()
        })
    })
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <shiro:hasPermission name="zhiliaoyiyuyue:add">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        </shiro:hasPermission>
    </div>
</script>
<script type="text/html" id="barDemo">
    <shiro:hasPermission name="zhiliaoyiyuyue:upd">
        <a href="javascript:void(0)" lay-event="edit"><i class="layui-icon layui-icon-edit"></i> </a>
    </shiro:hasPermission>
    <shiro:hasPermission name="zhiliaoyiyuyue:del">
        <a href="javascript:void(0)" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </shiro:hasPermission>
</script>
</body>
</html>
